using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

namespace NittiTre
{
    public partial class WhiteBoard : Form
    {
        Color c = new Color();
        List<GraphicsState> saveStates = new List<GraphicsState>();
        Point lastPoint = new Point();

        public WhiteBoard()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 3;
        }

        private void Form1_Click(object sender, EventArgs e)
        {
            if (((MouseEventArgs)e).Button == MouseButtons.Left)
            {
                Point p = Cursor.Position;
                drawPoint(p);
            }
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            
            if (e.Button == MouseButtons.Left)
            {
                Point p = Cursor.Position;
                drawPoint(p);
            }
        }

        private void drawPoint(Point p)
        {
            int size = int.Parse(comboBox2.SelectedItem.ToString());
            if (comboBox1.SelectedItem.ToString() == "Red")
            {
                c = Color.Red;
            }
            else if (comboBox1.SelectedItem.ToString() == "Green")
            {
                c = Color.Green;
            }
            else if (comboBox1.SelectedItem.ToString() == "Blue")
            {
                c = Color.Blue;
            }
            else if (comboBox1.SelectedItem.ToString() == "Black")
            {
                c = Color.Black;
            }
            else if (comboBox1.SelectedItem.ToString() == "White (Erase)")
            {
                c = Color.White;
            }
            
            System.Drawing.Pen myPen = new System.Drawing.Pen(c);
            Brush b = new SolidBrush(c);
            System.Drawing.Graphics formGraphics;
            formGraphics = this.CreateGraphics();
            myPen.Width = size;
            if (lastPoint.IsEmpty)
            {
                lastPoint = p;
            }
            //formGraphics.DrawEllipse(myPen, new Rectangle(p.X, p.Y, size, size));
            formGraphics.DrawLine(myPen, lastPoint, p);
            lastPoint = p;
            formGraphics.FillEllipse(b, p.X-(size/2), p.Y-(size/2), size, size);
            myPen.Dispose();
            formGraphics.Dispose();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Clear();
        }

        private void Clear()
        {
            this.CreateGraphics().Clear(Color.White);
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            
            if (e.KeyCode == Keys.PageUp)
            {
                if (this.Opacity < 0.9)
                {
                    this.Opacity += 0.1;
                }
                else if (this.Opacity < 1.0)
                {
                    this.Opacity = 0.99;
                }
            }
            else if (e.KeyCode == Keys.PageDown)
            {
                if (this.Opacity > 0.2)
                {
                    this.Opacity -= 0.1;
                }
                else if (this.Opacity > 0.1)
                {
                    this.Opacity = 0.1;
                }
            }
            else if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
            else if (e.KeyCode == Keys.Back)
            {
                Clear();
            }

        }

        private void redToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox1.SelectedItem = "Red";
        }

        private void blueToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox1.SelectedItem = "Blue";
        }

        private void greenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox1.SelectedItem = "Green";
        }

        private void blackToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox1.SelectedItem = "Black";
        }

        private void whiteeraseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox1.SelectedItem = "White (Erase)";
        }

        private void smallToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox2.SelectedIndex = 1;
        }

        private void mediumToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox2.SelectedIndex = 2;
        }

        private void largeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox2.SelectedIndex = 3;
        }

        private void hugeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox2.SelectedIndex = 4;
        }

        private void clearScreenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Clear();
        }

        private void massiveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox2.SelectedIndex = 5;
        }


        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.1;
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.2;
        }

        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.3;
        }

        private void toolStripMenuItem5_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.4;
        }

        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.5;
        }

        private void toolStripMenuItem7_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.7;
        }

        private void toolStripMenuItem8_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.8;
        }

        private void toolStripMenuItem9_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.9;
        }

        private void solidToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.99;
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            lastPoint = Point.Empty;
        }

    }
}